package cn.topevery.garden.wapi.scheduled;


import cn.topevery.garden.dal.logic.UpmsLogic;
import com.xxl.job.core.context.XxlJobHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class ScheduleService {

    /**
     * 1、简单任务示例（Bean模式）
     */
//    @XxlJob("firstJobHandler")
    public void firstJobHandler() throws Exception {

        XxlJobHelper.log("XXL-JOB, Hello World.");
        System.out.println("firstJobHandler 被调用！ at " + LocalDateTime.now());
        for (int i = 0; i < 5; i++) {
            XxlJobHelper.log("beat at:" + i);
            TimeUnit.SECONDS.sleep(1);
        }
    }

    @Autowired
    private UpmsLogic upmsLogic;

    //    @XxlJob("userSynchronization")
//    @Scheduled(cron = "0 0/5 * * * ?")
    public void userSynchronize() {
        boolean isSuccess = upmsLogic.userSynchronize();
        log.info("统一平台用户同步：{}", isSuccess);
    }
}
